package servlet.user;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.User;
import service.UserService;


@WebServlet("/user_login")
public class userlogin_Servlet extends HttpServlet {
	
	private	  UserService  userService  =  new  UserService();
	
	
	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		
		request.setCharacterEncoding("UTF-8");
		String  ue = request.getParameter("ue");
		String  password  =  request.getParameter("password");
		User  user  = userService.login(ue, password);
		if(user==null) {
			
			request.setAttribute("failMsg", "用户名、邮箱或者密码错误,请重新登录!");
			request.getRequestDispatcher("/user_login.jsp").forward(request, response);
			
		}else {
			
			request.getSession().setAttribute("user", user);
			
			request.getRequestDispatcher("/user_center.jsp").forward(request, response);
		}
		
		
	}

}
